//
//  SelfShowView.m
//  SIPphone
//
//  Created by wrt on 15-2-10.
//  Copyright (c) 2015年 wrtsoft. All rights reserved.
//

#import "SelfShowView.h"

@implementation SelfShowView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    self.beginpoint = [touch locationInView:self];
    [[self superview] bringSubviewToFront:self];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    CGPoint point = [[touches anyObject] locationInView:self];
    float dx = point.x - self.beginpoint.x;
    float dy = point.y - self.beginpoint.y;
    CGPoint newcenter = CGPointMake(self.center.x + dx, self.center.y + dy);
    float halfx = CGRectGetMidX(self.bounds);
    if(dx<0)
    {
        newcenter.x=MAX(halfx,newcenter.x);
    }
    else
    {
        newcenter.x=MIN(self.superview.bounds.size.width-halfx,newcenter.x);
    }
    float halfy=CGRectGetMidY(self.bounds);
    if(dy<0)
    {
        newcenter.y=MAX(newcenter.y,halfy);
    }
    else
    {
        newcenter.y=MIN(newcenter.y,self.superview.bounds.size.height-halfy);
    }
    self.center=newcenter;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
